#include <../inc/temperature_search.h>


float search_optimal_temp(const char *item_name){

    FILE *file = fopen("/root/code/temperature_db.csv","r");

    if(!file){
        return (-2);
    }

    char line[256];
    while(fgets(line,sizeof(line),file)){
        char name[50];
        float temp;
        sscanf(line, "%[^,],%f",name,&temp);

        if(strcmp(name,item_name)==0){
            fclose(file);
            return temp;
        }
    }

    fclose(file);
    return (-1);
}

